package org.bt.common.exception;

import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 统一处理controlleradvice无法捕获的异常
 * <p>
 * Created on 2021/8/22
 *
 * @author tongw
 */
@RestController
public class GlobalExceptionHandler {

    @RequestMapping("/error/400")
    public void error400(HttpServletRequest request) {
        throw ((AppRuntimeException) request.getAttribute("shiroHttpFilter.400"));
    }

    @SneakyThrows
    @RequestMapping("/error/500")
    public void error500(HttpServletRequest request) {
        throw ((Exception) request.getAttribute("shiroHttpFilter.500"));
    }
}
